<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateLearn extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('learn', ['comment' => '题目类别表']);
        $table->addColumn('title', 'string', array('limit' => 120, 'null' => true, 'comment' => '名称'))
            ->addColumn('create_id', 'integer', array('limit' => 30, 'default' => 0, 'comment' => '创建人id'))
            ->addTimestamps()
            ->addSoftDelete()
            ->addIndex(array('title'))
            ->create();


        $table = $this->table('learn_topic', ['comment' => '题库主题表(问题表)']);
        $table->addColumn('topic_title', 'string', array('limit' => 220, 'null' => true, 'comment' => '名称'))
            ->addColumn('learn_id', 'integer', array('limit' => 30, 'default' => 0, 'comment' => '题目归属id'))
            ->addColumn('learn_answer', 'string', array('limit' => 230, 'null'=>true, 'comment' => '问题答案'))
            ->addColumn('question_type', 'integer', array('limit' => 30, 'default' => 0, 'comment' => '问题题型(单选，多选，判断，填空)'))
            ->addColumn('answer_explain', 'string', array('limit' => 330, 'null'=>true, 'comment' => '答案解析'))
            ->addColumn('create_id', 'integer', array('limit' => 30, 'default' => 0, 'comment' => '创建人id'))
            ->addTimestamps()
            ->addSoftDelete()
            ->addIndex(array('topic_title'))
            ->create();


        $table = $this->table('learn_option', ['comment' => '问题选项表']);
        $table->addColumn('option_title', 'string', array('limit' => 220, 'null' => true, 'comment' => '名称'))
            ->addColumn('learn_id', 'integer', array('limit' => 30, 'default' => 0, 'comment' => '题目归属id'))
            ->addColumn('learn_topic_id', 'integer', array('limit' => 30, 'default' => 0, 'comment' => '问题归属id'))
            ->addColumn('create_id', 'integer', array('limit' => 30, 'default' => 0, 'comment' => '创建人id'))
            ->addTimestamps()
            ->addSoftDelete()
            ->addIndex(array('option_title'))
            ->create();
    }
}
